using UnityEngine;
using System.Collections;

public class Spuddable : MonoBehaviour {
	private bool pickedUp = false;
	public MonoBehaviour[] disableScripts;
	private bool isShot = false;
	private int timer;
	private int timeadd = 40;
	public bool iskinematic = false;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void ForcedUpdate () {
		while(timer > 0){
			timer--;
			if(timer == 0){
				if(!iskinematic){
					rigidbody.isKinematic = false;
				}
				for(int i = 0; i> disableScripts.Length; i++){
					if(disableScripts[i] != null)
					disableScripts[i].enabled = true;
				}
			}
		}
	}
	
	public bool GetPicked()	{return !pickedUp;}
	public void PickUp()	{pickedUp = true;}
	public void LetOut()	
	{
		pickedUp = false;
		isShot = true;
		for(int i = 0; i> disableScripts.Length; i++){
			if(disableScripts[i] != null)
			disableScripts[i].enabled = false;
		}
		
	}
	void OnCollisionEnter(Collision other){
		if(isShot && other.gameObject.GetComponent<TerrainCollider>() != null){
			rigidbody.freezeRotation = false;
			rigidbody.isKinematic = true;
			timer = timeadd + 1;
			isShot = false;
			//Landed
			//if(explode != null) explode(); Something something
		}
	}
	void OnCollisionExit(Collision other){
		if(other.gameObject.GetComponent<TerrainCollider>() != null && !pickedUp){
			rigidbody.isKinematic = false;
			
		}
	}
	
}
